package com.lily.aidouzixun.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.alibaba.fastjson.JSONObject;

/**
 * 文章信息，包括轮播条和Item条
 */
public class ArticleInfo implements Parcelable {

    /**
     * Json key
     */
    private static final String LDID_JSONKEY= "LDID";
    private static final String URID_JSONKEY= "URID";
    private static final String TITLE_JSONKEY= "Title";
    private static final String IMAGE_JSONKEY= "Image";
    private static final String PUBTIME_JSONKEY= "Pubtime";
    private static final String STATE_JSONKEY= "State";
    private static final String TYPE_JSONKEY= "Type";
    private static final String ISCAROUSEL_JSONKEY= "IsCarousel";
    private static final String SUPPORT_JSONKEY = "Support";
    private static final String BROWSE_JSONKEY = "Browse";
    private static final String OPPOSITION_JSONKEY = "Opposition";
    private static final String COMMENTS_JSONKEY = "Comments";
    private static final String IS_SUPPORT_JSONKEY = "isSupport";
    private static final String IS_COLLECT_JSONKEY = "isCollect";
    /**
     * 属性值
     */
    private String ldid;
    private String urid;
    private String title;
    private String imageUrl;
    private String pubtime;
    private int state;  //状态 1-可用;2-不可用
    private int type;	//状态 1-真实用户;2-匿名用户
    private int isCarousel;	//是否为轮播 1-是
    private int support;
    private int browse;
    private int opposition;
    private int comments;
    private int isSupport;  //是否点过赞，0-没有；1-点过
    private int isCollect;  //是否收藏过，0-没有；1-收藏过

    public String getUrid() {
        return urid;
    }

    public void setUrid(String urid) {
        this.urid = urid;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getPubtime() {
        return pubtime;
    }

    public void setPubtime(String pubtime) {
        this.pubtime = pubtime;
    }

    public String getLdid() {
        return ldid;
    }

    public void setLdid(String ldid) {
        this.ldid = ldid;
    }

    public int getIsCarousel() {
        return isCarousel;
    }

    public void setIsCarousel(int isCarousel) {
        this.isCarousel = isCarousel;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public int getComments() {
        return comments;
    }

    public void setComments(int comments) {
        this.comments = comments;
    }

    public int getIsCollect() {
        return isCollect;
    }

    public void setIsCollect(int isCollect) {
        this.isCollect = isCollect;
    }

    public int getIsSupport() {
        return isSupport;
    }

    public void setIsSupport(int isSupport) {
        this.isSupport = isSupport;
    }

    public int getBrowse() {
        return browse;
    }

    public void setBrowse(int browse) {
        this.browse = browse;
    }

    public int getOpposition() {
        return opposition;
    }

    public void setOpposition(int opposition) {
        this.opposition = opposition;
    }

    public int getSupport() {
        return support;
    }

    public void setSupport(int support) {
        this.support = support;
    }

    /**
     * 解析文章列表数据
     * @param jsonObj
     * @return
     */
    public static ArticleInfo parseInfo(JSONObject jsonObj) {
        if (jsonObj == null) {
            return null;
        }
        ArticleInfo longDistanceInfo = new ArticleInfo();
        if (jsonObj.has(LDID_JSONKEY)) {
            longDistanceInfo.setLdid(jsonObj.optString(LDID_JSONKEY));
        }
        if (jsonObj.has(URID_JSONKEY)) {
            longDistanceInfo.setUrid(jsonObj.optString(URID_JSONKEY));
        }
        if (jsonObj.has(TITLE_JSONKEY)) {
            longDistanceInfo.setTitle(jsonObj.optString(TITLE_JSONKEY));
        }
        if (jsonObj.has(IMAGE_JSONKEY)) {
            longDistanceInfo.setImageUrl(jsonObj.optString(IMAGE_JSONKEY));
        }
        if (jsonObj.has(PUBTIME_JSONKEY)) {
            longDistanceInfo.setPubtime(jsonObj.optString(PUBTIME_JSONKEY));
        }
        if (jsonObj.has(STATE_JSONKEY)) {
            longDistanceInfo.setState(Integer.parseInt(jsonObj.optString(STATE_JSONKEY)));
        }
        if (jsonObj.has(TYPE_JSONKEY)) {
            longDistanceInfo.setType(Integer.parseInt(jsonObj.optString(TYPE_JSONKEY)));
        }
        if (jsonObj.has(ISCAROUSEL_JSONKEY)) {
            longDistanceInfo.setIsCarousel(Integer.parseInt(jsonObj.optString(ISCAROUSEL_JSONKEY)));
        }
        if (jsonObj.has(SUPPORT_JSONKEY)) {
            longDistanceInfo.setSupport(Integer.parseInt(jsonObj.optString(SUPPORT_JSONKEY)));
        }
        if (jsonObj.has(BROWSE_JSONKEY)) {
            longDistanceInfo.setBrowse(Integer.parseInt(jsonObj.optString(BROWSE_JSONKEY)));
        }
        if (jsonObj.has(OPPOSITION_JSONKEY)) {
            longDistanceInfo.setOpposition(Integer.parseInt(jsonObj.optString(OPPOSITION_JSONKEY)));
        }
        if (jsonObj.has(COMMENTS_JSONKEY)) {
            longDistanceInfo.setComments(Integer.parseInt(jsonObj.optString(COMMENTS_JSONKEY)));
        }
        if (jsonObj.has(IS_SUPPORT_JSONKEY)) {
            longDistanceInfo.setIsSupport(jsonObj.optInt(IS_SUPPORT_JSONKEY));
        }
        if (jsonObj.has(IS_COLLECT_JSONKEY)) {
            longDistanceInfo.setIsCollect(jsonObj.optInt(IS_COLLECT_JSONKEY));
        }
        return longDistanceInfo;
    }

    /**
     * 序列化实体类
     */
    public static final Parcelable.Creator<ArticleInfo> CREATOR = new Creator<ArticleInfo>() {
        public ArticleInfo createFromParcel(Parcel source) {
            ArticleInfo longDistanceInfo = new ArticleInfo();
            longDistanceInfo.ldid = source.readString();
            longDistanceInfo.urid = source.readString();
            longDistanceInfo.title = source.readString();
            longDistanceInfo.imageUrl = source.readString();
            longDistanceInfo.pubtime = source.readString();
            longDistanceInfo.state = source.readInt();
            longDistanceInfo.type = source.readInt();
            longDistanceInfo.isCarousel = source.readInt();
            longDistanceInfo.support = source.readInt();
            longDistanceInfo.browse = source.readInt();
            longDistanceInfo.opposition = source.readInt();
            longDistanceInfo.comments = source.readInt();
            longDistanceInfo.isSupport = source.readInt();
            longDistanceInfo.isCollect = source.readInt();
            return longDistanceInfo;
        }

        public ArticleInfo[] newArray(int size) {
            return new ArticleInfo[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(ldid);
        parcel.writeString(urid);
        parcel.writeString(title);
        parcel.writeString(imageUrl);
        parcel.writeString(pubtime);
        parcel.writeInt(state);
        parcel.writeInt(type);
        parcel.writeInt(isCarousel);
        parcel.writeInt(support);
        parcel.writeInt(browse);
        parcel.writeInt(opposition);
        parcel.writeInt(comments);
        parcel.writeInt(isSupport);
        parcel.writeInt(isCollect);
    }
}
